
import java.util.ArrayList;

/**
 *
 * @author kaszubm9
 */
public class Journey {

    private int startStop;
    private int endStop;
    private int route;
    private int noOfBusStopsBetween;
    private int departureTime;
    private int arrivalTime;
    TimetableInfo.timetableKind kind;

    //one Journey one route
    public Journey(int startStop, int endStop, int route,
        int noOfBusStopsBetween, TimetableInfo.timetableKind kind) {
        this.startStop=startStop;
        this.endStop=endStop;
        this.route=route;
        this.noOfBusStopsBetween=noOfBusStopsBetween;
        this.departureTime=0;
        this.arrivalTime=0;
        this.kind=kind;
    }
    /**
     * false by default, changes change to true if the passenger has to have to
     * change in Marple
     * @param change
     */

    
    public int getNoOfBusStopsBetween() {
        return this.noOfBusStopsBetween;
    }
    
    public  int getRoute() {
        return this.route;
    }

    public int getStartStop() {
        return this.startStop;
    }

    int getEndStop() {
        return this.endStop;
    }


    int getArrivalTime() {
        return this.arrivalTime;
    }

    int getDepoTime() {
        return this.departureTime;
    }        


     public void setDepAndArrivalTime(int chosenTime) {
         int[] stops=NameInfo.getStopsProperOrder(this.route);
         int[][] array=Timetables.getTimetableArray(this.route, this.kind, stops.length);
        /* for(int i=0;i<array.length;i++){
             for(int j=0;j<5;j++)
                 System.out.print(array[i][j]+"   ");
             System.out.println();}*/
         int l=0, i=0,k=0;
         while(this.startStop!=stops[l])
            l++;
         while(array[i][l]<chosenTime || array[i][l]==5940){
             i++;
         }
         this.departureTime=array[i][l];

         while(this.endStop!=stops[k])
            k++;
         this.arrivalTime=array[i][k];
         if(this.arrivalTime==0)
                 this.arrivalTime=this.departureTime;
    }


    @Override
    public String toString(){
        return "start stop: "+ this.startStop+"("+BusStopInfo.getName(this.startStop)+
                "),"+ " end stop : "+this.endStop+"("+BusStopInfo.getName(this.endStop)+
                "),"
                + " start/end route: "+ BusStopInfo.getRouteName(this.route)
                + "/" + BusStopInfo.getRouteName(this.route)
                + ", number of stops in between: "+this.noOfBusStopsBetween +"";
    }
}
